<?php
include('../config.php');
if (!isset($admin_username))
{
	// Not installed:
	?>
	<meta http-equiv="refresh" content="0;url=../install.php" />
	<?php
	exit;
}

if (isset($_COOKIE['admin']))
{
	// No need to be here:
	?>
	<meta http-equiv="refresh" content="0;url=./index.php" />
	<?php
	exit;
}

if (isset($_POST['submit']))
{
	// Check if username and password are correct:
	$user = $_POST['username'];
	$pass = md5($_POST['password']);
	
	if ($user == $admin_username && $pass == $admin_password)
	{
		setcookie('admin', 'true', time()+3600);
		?>
		<meta http-equiv="refresh" content="0;url=./index.php" />
		<?php
		exit;
	}
	else
	{
		$error = 'Incorrect username or password, please try again.';
	}
}
?>
<html>
	<head>
		<title>Login</title>
		<link rel="stylesheet" href="./style/style.css" type="text/css">
	</head>
	<body>
		<div id="header">
		</div>
		<div id="container">
			<div id="content">
				<?php
				echo '<div style="color: red; font-weight: bold;">' . $error . '</div>';
				?>
				<p>In order to access the Admin Panel you must first log in, please enter your Username and Password in the form below.</p>
				<form action="login.php" method="post">
					<strong>Username:</strong><br />
					<input type="text" name="username" style="font-family: Verdana; font-size: 12px; width: 300px;">
					<br />
					<strong>Password:</strong><br />
					<input type="password" name="password" style="font-family: Verdana; font-size: 12px; width: 300px;"><br />
					<input type="submit" name="submit" value="Login">
				</form>
			</div>
		</div>
	</body>
</html>